<template>
    <Modal
            width="800"
            v-model="visible"
            :title="title"
            :key="key"
    >
        <div style="width: 80%;padding-left: 10%;padding-right: 10%">
            <Form :label-width="130" ref="formValidate" :model="formValidate"
                  :rules="ruleValidate" :disabled="disableSubmit">
                <Form-item label="流程节点code:" prop="nodecode">
                    <Input v-model="formValidate.nodecode" style="width:300px" readonly/>
                </Form-item>
                <Form-item label="流程节点名称:" prop="nodename">
                    <Input v-model="formValidate.nodename" style="width:300px"/>
                </Form-item>
                <Form-item label="任务审批角色:" prop="rolecodes">
                    <c-role-select v-model="formValidate.rolecodes" :width="300" :multiple="true"/>
                </Form-item>
                <Form-item label="流程阶段:" prop="processstage">
                    <c-dict-select v-model="formValidate.processstage" dictCode="processphase" :width="300"
                                   :clearable="true"/>
                </Form-item>
                <Form-item label="数据类型:" prop="approvemodal">
                    <c-dict-select v-model="formValidate.approvemodal" dictCode="approvemodal" :width="300"
                                   :clearable="true"/>
                </Form-item>
                <Form-item label="办理模块:" prop="busmodal">
                    <c-dict-select v-model="formValidate.busmodal" dictCode="busmodal" :width="300" :clearable="true"/>
                </Form-item>
                <Form-item label="是否校验要件:" prop="checkfile">
                    <c-dict-select v-model="formValidate.checkfile" dictCode="yesorno" :width="300" :clearable="true"/>
                </Form-item>
                <Form-item label="是否第一节点:" prop="firstnode">
                    <c-dict-select v-model="formValidate.firstnode" dictCode="yesorno" :width="300" :clearable="true"/>
                </Form-item>
                <Form-item label="审批属地:" prop="areacode">
                    <c-dict-select v-model="formValidate.areacode" dictCode="nodeareacode" :width="300" :clearable="true"/>
                </Form-item>
                <Form-item label="排序:" prop="sort">
                    <InputNumber :max="100" :min="0" v-model="formValidate.sort" style="width:300px"></InputNumber>
                </Form-item>
            </Form>
        </div>
        <div slot="footer">
            <Button @click="cancel">取消</Button>
            <template v-if="!disableSubmit">
                <Button type="primary" @click="ok">确定</Button>
            </template>
        </div>
    </Modal>
</template>

<script>
    import {getAction, postAction} from '@/api/request'

    export default {
        data() {
            const validateMobile = (rule, value, callback) => {
                if (!this.formValidate.sort) {
                    callback(new Error('排序不能为空'));
                } else {
                    callback();
                }
            };
            return {
                modal1: false,
                title: "",
                disabled: false,
                visible: false,
                disableSubmit: false,
                formValidate: {
                    sort: null
                },
                key: "",
                ruleValidate: {
                    nodecode: [
                        {required: true, message: '流程节点code不能为空', trigger: 'blur'}
                    ],
                    nodename: [
                        {required: true, message: '流程节点名称不能为空', trigger: 'blur'}
                    ],
                    sort: [
                        {required: true, message: '排序不能为空', trigger: 'blur', validator: validateMobile}
                    ],
                },
                url: "",
            }
        },
        methods: {
            add(processkey) {
                this.url = "/api/ac/subsistence/extActNodeConfigService/insert";
                this.visible = true;
                this.formValidate = Object.assign({}, {});
                this.formValidate.processkey = processkey;
            },
            ok() {
                var that = this;
                this.$refs['formValidate'].validate((valid) => {
                    if (valid) {
                        that.submitFrom();
                    }
                })
            },

            submitFrom() {
                var that = this;
                that.Loading = true;
                postAction(this.url, this.formValidate).then((res) => {
                    if (res.data.errcode != 0) {
                        this.$Message.error(res.data.errmsg);
                    } else {
                        this.$emit('ok');
                        this.visible = false;
                    }
                }).finally(() => {
                    that.Loading = false;
                });
            },
            cancel() {
                this.visible = false;
            },
            edit(row) {
                let that = this;
                this.disabled = true;
                this.url = "/api/ac/subsistence/extActNodeConfigService/update";
                this.visible = true
                this.formValidate = Object.assign({}, row);
                if (!this.formValidate.sort) {
                    that.formValidate.sort = null;
                }
            },
        }
    }
</script>

<style scoped>

</style>
